/*
 * @(#)QueryResultSet.java        0.1 13-Feb-2009
 *
 * Copyright 2008 Thomas Ford. All rights reserved.
 */


package edu.napier.soc.xfdm.parser;

import java.text.DateFormat;
import java.util.*;

/**
 * @author Thomas Ford
 * @version 0.1, 13-Feb-2009
 */
public class QueryResultSet {

	private final Queue<QueryResult> queries;
	private final Queue<String> events;
	private final DateFormat df;

	public QueryResultSet() {
		queries = new LinkedList<QueryResult>();
		events = new LinkedList<String>();
		df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
	}

	public void addEvent(String message) {
		String date = df.format(new Date());
		String event = String.format("[ %1$s ] %2$s", date, message);
		events.add(event);
	}

	public boolean add(QueryResult q) {
		return queries.add(q);
	}

	public String nextEvent() {
		return events.poll();
	}

	public QueryResult nextQueryResult() {
		return queries.poll();
	}

	public List<QueryResult> getQueryResults() {
		return Collections.unmodifiableList((List<QueryResult>) queries);
	}

	public List<String> getEvents() {
		return Collections.unmodifiableList((List<String>) events);
	}

	public int size() {
		return queries.size();
	}

	public void clear() {
		queries.clear();
		events.clear();
	}
}
